package models;

import models.admin.AdminUser;
import models.constants.DeletedStatus;
import models.enums.SettlementStatus;
import models.enums.StockInStatus;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by liming on 16/7/16.
 * 采购入库
 */
@Entity
@Table(name = "admin_stock_in")
public class AdminStockIn extends BaseModel {

    /**
     * 入库单号
     */
    @Column(name = "code")
    public String code;

    /**
     * 采购日期
     */
    @Column(name = "purchase_date")
    @Temporal(TemporalType.TIMESTAMP)
    public Date purchaseDate;

    /**
     * 入库日期
     */
    @Column(name = "in_date")
    @Temporal(TemporalType.TIMESTAMP)
    public Date inDate;

    /**
     * 供应商
     */
    @ManyToOne
    @JoinColumn(name = "admin_supplier_id")
    public AdminSupplier adminSupplier;

    /**
     * 运费
     */
    public Double freight = 0D;

    /**
     * 采购金额
     */
    @Column(name = "total_amount")
    public Double totalAmount= 0D;

    /**
     * 备注
     */
    @Column(name = "remark")
    public String remark;

    /**
     * 采购入库单状态
     */
    @Column(name = "stock_in_status")
    @Enumerated(EnumType.STRING)
    public StockInStatus stockInStatus;

    /**
     * 审核人
     */
    @ManyToOne
    @JoinColumn(name = "audit_user_id")
    public AdminUser auditUser;

    /**
     * 审核时间
     */
    @Column(name = "audit_date")
    @Temporal(TemporalType.TIMESTAMP)
    public Date auditDate;

    /**
     * 审核备注
     */
    @Column(name = "audit_remark")
    public String auditRemark;

    /**
     * 结算状态
     */
    @Column(name = "settlement_status")
    @Enumerated(EnumType.STRING)
    public SettlementStatus settlementStatus;

    /**
     * 结算人
     */
    @ManyToOne
    @JoinColumn(name = "settlement_user_id")
    public AdminUser settlementUser;

    /**
     * 结算时间
     */
    @Column(name = "settlement_date")
    @Temporal(TemporalType.TIMESTAMP)
    public Date settlementDate;

    /**
     * 结算备注
     */
    @Column(name = "settlement_remark")
    public String settlementRemark;


    /**
     * 版本号
     */
    @Version
    public Integer version = 0;

    /**
     * 删除状态
     */
    @Column(name = "deleted_status")
    public DeletedStatus deletedStatus;

    /**
     * 根据ID查询采购单
     *
     */
    public  static AdminStockIn findByInId(long id){
        return AdminStockIn.find("id=? and deletedStatus=?",id,DeletedStatus.UN_DELETED).first();
    }

}
